package com.example.homework.fragment;

import android.content.Context;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.homework.R;
import com.example.homework.adapter.FocusAdapter;
import com.example.homework.bean.FocusData;

import java.util.ArrayList;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link FocusFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class FocusFragment extends Fragment {
    private RecyclerView recyclerViewFocus;
    private ArrayList<FocusData> list1 = new ArrayList<>();
    private Context context1;
    private FocusAdapter focusAdapter;

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    public FocusFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment FocusFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static FocusFragment newInstance(String param1, String param2) {
        FocusFragment fragment = new FocusFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_focus, container, false);
        recyclerViewFocus = view.findViewById(R.id.focus_recyclerView);
        initData();
        initView();
        return view;
    }

    private void initView() {
        context1 = this.getContext();
        focusAdapter = new FocusAdapter(context1,list1);
        LinearLayoutManager layoutManager = new LinearLayoutManager(context1,LinearLayoutManager.VERTICAL,false);
        recyclerViewFocus.setLayoutManager(layoutManager);
        recyclerViewFocus.setAdapter(focusAdapter);

    }

    private void initData() {
        list1.add(new FocusData(R.drawable.yangyang,"杨洋","[99]你是世界上最帅的帅哥，有钱有实力！","5:20"));
        list1.add(new FocusData(R.drawable.dog5,"旺财","[3]走，请你吃麻辣烫！","22:00"));
        list1.add(new FocusData(R.drawable.pig,"大宝","[2]走，请你吃螺蛳粉！","18:00"));
        list1.add(new FocusData(R.drawable.pang,"小胖","[6]走，请你吃饭！","11:00"));
        list1.add(new FocusData(R.drawable.tiger,"小虎","[9]走，看帅哥去！","8:00"));
        list1.add(new FocusData(R.drawable.cat,"小宝","[3]走，请你喝奶茶！","15:00"));
        list1.add(new FocusData(R.drawable.dog8,"小手","[5]走，请你去旅游！","23:00"));
        list1.add(new FocusData(R.drawable.dog7,"小多","[8]走，请你去上网！","24:00"));
        list1.add(new FocusData(R.drawable.dog9,"妈妈","[6]回家吃饭了！","18:30"));
        list1.add(new FocusData(R.drawable.dog2,"小音","[7]开始购物了！","0:00"));

    }
}